package com.cly.controller;

import com.cly.base.controller.BaseController;
import com.cly.dto.ProblemInsertDto;
import com.cly.entity.Problem;
import com.cly.result.JsonRequest;
import com.cly.service.IProblemService;
import com.cly.vo.ProblemDetailVo;
import com.cly.vo.ProblemVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 题目表 控制器
 *
 * @author by 春风能解释
 * <p>
 * 2024-06-05
 */
@RestController
@RequestMapping("/pro")
@Tag(name = "题目表控制类", description = "题目表操作访问接口")
public class ProblemController extends BaseController<IProblemService, Problem> {

    /**
     * 分页查询题目
     *
     * @param current 页码
     * @param size    页长
     * @param problem 条件
     * @return JSON
     */
    @GetMapping("/list")
    @Operation(summary = "分页查询题目")
    public JsonRequest<List<ProblemVo>> lookProblem(
            @Parameter(description = "页码", required = true)
            @RequestParam Integer current,
            @Parameter(description = "页长", required = true)
            @RequestParam Integer size,
            @Parameter(description = "条件", required = true)
            Problem problem) {
        return baseService.lookProblem(current, size, problem);
    }


    /**
     * 查看题目详情
     *
     * @param id ID
     * @return JSON
     */
    @GetMapping("/detail")
    @Operation(summary = "查看题目详情")
    public JsonRequest<ProblemDetailVo> lookProblemDetail(
            @Parameter(description = "ID", required = true)
            @RequestParam Long id) {
        return baseService.lookProblemDetail(id);
    }

    /**
     * 添加一条题目
     *
     * @param problem 题目实体
     * @return JSON
     */
    @PostMapping
    @Operation(summary = "添加一条题目")
    public JsonRequest<Integer> addOneProblem(
            @Parameter(description = "题目实体", required = true)
            @RequestBody ProblemInsertDto problem) {
        return baseService.addOneProblem(problem);
    }

    /**
     * 修改一条题目
     *
     * @param problem 题目实体
     * @return JSON
     */
    @PutMapping
    @Operation(summary = "修改一条题目")
    public JsonRequest<Integer> updateOneProblem(
            @Parameter(description = "题目实体", required = true)
            @RequestBody ProblemInsertDto problem) {
        return baseService.updateOneProblem(problem);
    }

    /**
     * 批量删除题目
     *
     * @param ids id数组
     * @return JSON
     */
    @DeleteMapping
    @Operation(summary = "批量删除题目")
    public JsonRequest<Integer> deleteProblems(
            @Parameter(description = "id数组", required = true)
            @RequestBody List<Long> ids) {
        return baseService.deleteProblems(ids);
    }
}




